@import "../../themes/ionic.globals.ios";

// iOS Toolbar
// --------------------------------------------------

/// @prop - Order of the toolbar elements
$toolbar-order-ios: (
  back-button: 0,
  menu-toggle-start: 1,
  buttons-left: 2,
  buttons-start: 3,
  content: 4,
  buttons-end: 5,
  buttons-right: 6,
  menu-toggle-end: 7,
);

/// @prop - Font size of the toolbar button
$toolbar-ios-button-font-size:              1.7rem !default;

/// @prop - Font size of the toolbar title
$toolbar-ios-title-font-size:               1.7rem !default;

/// @prop - Font weight of the toolbar title
$toolbar-ios-title-font-weight:             600 !default;

/// @prop - Text alignment of the toolbar title
$toolbar-ios-title-text-align:              center !default;

/// @prop - Text color of the toolbar title
$toolbar-ios-title-text-color:              color-contrast($colors-ios, $toolbar-ios-background) !default;

/// @prop - Text color of the toolbar button
$toolbar-ios-button-color:                  color-contrast($colors-ios, $toolbar-ios-background, ios) !default;

/// @prop - Border radius of the toolbar button
$toolbar-ios-button-border-radius:          4px !default;

/// @prop - Height of the navigation bar
$navbar-ios-height:                         $toolbar-ios-height !default;


.toolbar-ios {
  padding: $toolbar-ios-padding;

  min-height: $toolbar-ios-height;
}


// iOS Toolbar Background
// --------------------------------------------------

.toolbar-background-ios {
  background: $toolbar-ios-background;
}


// iOS Header / Footer Borders
// --------------------------------------------------

.header-ios .toolbar-background-ios,
.footer-ios .toolbar-background-ios {
  border-style: solid;
  border-color: $toolbar-ios-border-color;
}

.header-ios .toolbar-ios:last-child .toolbar-background-ios {
  border-width: 0 0 $hairlines-width;
}

.footer-ios .toolbar-ios:first-child .toolbar-background-ios {
  border-width: $hairlines-width 0 0;
}

.header-ios[no-border] .toolbar-ios:last-child .toolbar-background-ios {
  border-bottom-width: 0;
}

.footer-ios[no-border] .toolbar-ios:first-child .toolbar-background-ios {
  border-top-width: 0;
}


// iOS Toolbar Content
// --------------------------------------------------

.toolbar-content-ios {
  flex: 1;
  order: map-get($toolbar-order-ios, content);

  min-width: 0;
}

.toolbar-title-ios {
  font-size: $toolbar-ios-title-font-size;
  font-weight: $toolbar-ios-title-font-weight;
  text-align: $toolbar-ios-title-text-align;
  color: $toolbar-ios-title-text-color;

  pointer-events: auto;
}

.toolbar-ios ion-title {
  position: absolute;
  top: 0;
  left: 0;

  padding: 0 90px 1px;

  width: 100%;
  height: 100%;

  transform: translateZ(0);

  pointer-events: none;
}

@mixin ios-toolbar-theme($color-name, $color-base, $color-contrast) {
  .toolbar-ios-#{$color-name} {

    .toolbar-background-ios {
      background: $color-base;
    }

    .toolbar-title-ios,
    .bar-button-clear-ios,
    .bar-button-default-ios {
      color: $color-contrast;
    }

    @each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
      @include ios-bar-button-default($color-name, $color-base, $color-contrast);
      @include ios-bar-button-outline($color-name, $color-base, $color-contrast);
      @include ios-bar-button-solid($color-name, $color-base, $color-contrast);
    }
  }
}


// iOS Toolbar Button Placement
// --------------------------------------------------

.bar-buttons-ios {
  order: map-get($toolbar-order-ios, buttons-start);

  transform: translateZ(0);
}

.bar-buttons-ios[left] {
  order: map-get($toolbar-order-ios, buttons-left);
}

.bar-buttons-ios[end] {
  order: map-get($toolbar-order-ios, buttons-end);

  text-align: right;
}

.bar-buttons-ios[right] {
  order: map-get($toolbar-order-ios, buttons-right);

  text-align: right;
}


// iOS Toolbar Button Default
// --------------------------------------------------

.bar-button-ios {
  padding: 0 4px;

  height: 32px;

  border: 0;
  border-radius: $toolbar-ios-button-border-radius;
  font-size: $toolbar-ios-button-font-size;
}

@mixin ios-bar-button-default($color-name, $color-base, $color-contrast) {

  .bar-button-#{$color-name}-ios,
  .bar-button-default.bar-button-ios-#{$color-name},
  .bar-button-clear-ios-#{$color-name} {
    color: $color-base;
    background-color: transparent;

    &:hover:not(.disable-hover) {
      color: $color-base;
    }

    &.activated {
      opacity: .4;
    }
  }

}


// iOS Toolbar Button Outline
// --------------------------------------------------

.bar-button-outline-ios {
  border-width: 1px;
  border-style: solid;
  border-color: $toolbar-ios-button-color;
  color: $toolbar-ios-button-color;
  background-color: transparent;

  &:hover:not(.disable-hover) {
    opacity: .4;
  }

  &.activated {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    background-color: $toolbar-ios-button-color;
  }
}

@mixin ios-bar-button-outline($color-name, $color-base, $color-contrast) {

  .bar-button-outline-ios-#{$color-name} {
    $fg-color: $color-base;
    border-color: $fg-color;
    color: $fg-color;
    background-color: transparent;

    &.activated {
      color: $color-contrast;
      background-color: $fg-color;
    }
  }

}


// iOS Toolbar Button Solid
// --------------------------------------------------

.bar-button-solid-ios {
  color: color-contrast($colors-ios, $toolbar-ios-button-color);
  background-color: $toolbar-ios-button-color;

  &:hover:not(.disable-hover) {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    opacity: .4;
  }

  &.activated {
    color: color-contrast($colors-ios, $toolbar-ios-button-color);
    background-color: color-shade($toolbar-ios-button-color);
    opacity: .4;
  }
}

@mixin ios-bar-button-solid($color-name, $color-base, $color-contrast) {

  .bar-button-solid-ios-#{$color-name} {
    color: $color-contrast;
    background-color: $color-base;

    &.activated {
      color: $color-contrast;
      background-color: color-shade($color-base);
    }
  }

}


// iOS Toolbar Button Icon
// --------------------------------------------------

.bar-button-ios.bar-button-icon-left ion-icon {
  padding-right: .3em;

  font-size: 1.4em;
  line-height: .67;

  pointer-events: none;
}

.bar-button-ios.bar-button-icon-right ion-icon {
  padding-left: .4em;

  font-size: 1.4em;
  line-height: .67;

  pointer-events: none;
}

.bar-button-ios[icon-only] {
  padding: 0;

  min-width: .9em;
}

.bar-button-ios[icon-only] ion-icon {
  padding: 0 .1em;

  font-size: 1.8em;
  line-height: .67;

  pointer-events: none;
}


// iOS Toolbar Back Button
// --------------------------------------------------

.back-button-ios {
  overflow: visible;

  order: map-get($toolbar-order-ios, back-button);

  margin: 0;

  min-height: 3.2rem;

  line-height: 1;
  transform: translateZ(0);
}

.back-button-icon-ios {
  display: inherit;

  margin: 0;
  margin-top: -1px;

  min-width: 18px;

  font-size: 3.4rem;
}

.back-button-text-ios {
  letter-spacing: -.01em;
}


// iOS Toolbar Menu Toggle
// --------------------------------------------------

.bar-button-menutoggle-ios {
  order: map-get($toolbar-order-ios, menu-toggle-start);

  margin: 0 6px;
  padding: 0;

  min-width: 36px;

  ion-icon {
    padding: 0 6px;

    font-size: 2.8rem;
  }
}

.bar-button-menutoggle-ios[end],
.bar-button-menutoggle-ios[right] {
  order: map-get($toolbar-order-ios, menu-toggle-end);
}


// iOS Toolbar Color Generation
// --------------------------------------------------

@include ios-bar-button-default(default, $toolbar-ios-button-color, color-contrast($colors-ios, $toolbar-ios-button-color, ios));
@include ios-bar-button-default(clear, $toolbar-ios-button-color, color-contrast($colors-ios, $toolbar-ios-button-color, ios));

@each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {
  @include ios-toolbar-theme($color-name, $color-base, $color-contrast);
  @include ios-bar-button-default($color-name, $color-base, $color-contrast);
  @include ios-bar-button-outline($color-name, $color-base, $color-contrast);
  @include ios-bar-button-solid($color-name, $color-base, $color-contrast);
}


// iOS strong Button
// --------------------------------------------------

.bar-button-strong-ios {
  font-weight: $button-ios-strong-font-weight;
}
